#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>
#include <QPixmap>
#include <QVector>
#include <QList>
#include <QTime>
#include <QPainter>
#include <QMouseEvent>
#include <QScreen>
#include <QKeyEvent>
#include <QApplication>
#include <QtGlobal>
#include <QRandomGenerator>
class renwu : public QWidget
{
    Q_OBJECT
public:
    enum class zhuangtai
    {
        kongxian,
        paodong,
        youpaodong,
        houkongfan,
        youkongxian,
        gongji
    };
    struct Diren
    {
        QPoint position;
        int currentFrame;
    };
    struct Jinshizi
    {
        QPoint position;
    };

   renwu(QWidget *parent = nullptr);
    ~renwu() override;

private :
    bool checkCollision(const QPoint &enemyPos, const QPixmap &enemyPixmap, const QPoint &playerPos, const QPixmap &playerPixmap, double enemyScale, double playerScale);
    void handleCollision();

    void paintEvent(QPaintEvent *) override;
    void keyPressEvent(QKeyEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;


    void kaishidonghua();
    void huidaokongxian();
    void jiazaidonghuazhen(const QString &prefix, int count, QVector<QPixmap> &zhen, QVector<QSize> &sizes);
    void kaishijiazaizhen();

    void createDiren();
    void createJinshizi();
    void jiazaizhen();

    void updateXueliangAnimation();
    void updatedoro();

    void xiandingweizhi(const QPoint &pos);

    double doroScaleFactor;
    QVector<QPixmap> dorozhen;
    int doroIndex;
    QTimer doroTimer;
    QVector<QSize> doroSize;

    QTimer direnTimer;
    QVector<QPixmap> direnFrames;
    QVector<QSize> direnzhenchicun;
    QList<Diren> direnList;

    QTimer xueliangTimer;
    QVector<QSize> xueliangzhenchicun;
    QPixmap xueliang;
    QVector<QPixmap> xueliangAnimationFrames;
    int xueliangAnimationIndex;
    int xueliangToAnimate;

    QPixmap jinshiziPixmap;
    QList<Jinshizi> jinshiziList;
    QTimer jinshiziTimer;

    QPixmap background;

    QPixmap woodPost;
    int woodPostHealth;
    int playerHealth;

    bool zhenjiazaiqingkuang;
    QTimer donghuashijian;
    zhuangtai dangqianzhuangtai;
    int dangqianzhenshu;

    QVector<QPixmap> kongxianzhen;
    QVector<QSize> kongxianzhenchicun;

    QVector<QPixmap> benpaozhen;
    QVector<QSize> benpaozhenchicun;

    QVector<QPixmap> youpaodongzhen;
    QVector<QSize> youpaodongzhenchicun;

    QVector<QPixmap> houkongfanzhen;
    QVector<QSize> houkongfanzhenchicun;

    QVector<QPixmap> youkongxianzhen;
    QVector<QSize> youkongxianzhenchicun;

    QVector<QPixmap> gongjizhen;
    QVector<QSize> gongjizhenchicun;




    QPoint tuozhuaiweizhi;



    int backflipStartY;
    int backflipYOffset;

    bool isFirstPressA;
    bool isFirstPressD;

    QTime lastPressATime;
    QTime lastPressDTime;

    bool isAPressed;
    bool isDPressed;

    bool isALongPressed;
    bool isDLongPressed;

    int playerX;
    int playerY;

};

#endif // WIDGET_H
